package com.okcl.dto;

import lombok.Data;

/**
 * 统一后端向前端返回的数据格式
 */
@Data
public class Result {
    public static final Integer ERROR_CODE = 500;
    public static final String ERROR_MSG = "error";
    private static final Integer SUCCESS_CODE = 200;
    private static final String SUCCESS_MSG = "success";
    private Integer code;
    private String msg;
    private Object data;

    public static Result ok(Object data) {
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setMsg(SUCCESS_MSG);
        result.setData(data);
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(ERROR_CODE);
        result.setMsg(msg);
        return result;
    }

    public static Result ok() {
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setMsg(SUCCESS_MSG);
        result.setData(null);
        return result;
    }
}